package com.bot.importer.test;

import static org.junit.Assert.*;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.bot.beans.User;
import com.bot.utils.CmsGetNameChUtil;
import com.bot.utils.DateUtils;

/**
 * @author zhaoyan
 *
 *	2020年2月29日
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring-context.xml")
public class ImportData {
	
	@Resource
	private  RedisTemplate redisTemplate;

	@Test
	public void test() {
		
		long begin = System.currentTimeMillis();
		
		//	不绑定的方式
		//ValueOperations ops = redisTemplate.opsForValue();
		
		//	绑定hash
		BoundHashOperations ops = redisTemplate.boundHashOps("user_hash");
		
		
		for (int i = 0; i < 50000; i++) {
			
			User user = new User();
			
			user.setId(i);
			
			user.setName(CmsGetNameChUtil.getChineseName());
			
			user.setEmail(CmsGetNameChUtil.getEmail());
			
			user.setSex(CmsGetNameChUtil.getSex());
			
			user.setPhone(CmsGetNameChUtil.getPhone());
			
			user.setDate(DateUtils.randomDate("1949-01-01 00:00:00", "2010-01-01 00:00:00"));
			
			//	存值
			//ops.set(user.getId() + "", user);
			
			ops.put(user.getId() + "", user.toString());
			
		}
		
		long end = System.currentTimeMillis();
		
		System.out.println("耗时"+(end -begin) +"ms");
		
	}

}
